package com.vince.model.domain;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.vince.model.service.UserService;
import com.vince.util.DBUtil;

/**
 *  用户注册
 * @author susp
 *
 */
@WebServlet("/servlet/registerservlet")
public class RegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
 

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       System.out.println("hello world");
       String name=request.getParameter("name");
       String pwd=request.getParameter("pwd");
       String type=request.getParameter("usertype").trim();
       User user=new User();
       user.setUsername(name);
       user.setPassword(pwd);
       user.setUsertype(Integer.valueOf(type));    
       //调用service
       UserService us=new UserService();
       us.addUser(user);   
       request.setAttribute("message", "注册成功");
       request.getRequestDispatcher("/view/share/register/success.jsp").forward(request, response);
       
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
